package com.freesun.shop.aspect;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class IndexImgAspect {

    @Autowired
    private StringRedisTemplate redisTemplate;
    /**
     * 清除indexImg在redis 里面的缓存数据
     * 1.前置通知
     * 2.后置通知
     */
     /* +"or" +
            "execution(* com.freesun.shop.service.imp.IndexImgServiceImpl.update*(..))"
            +"or" +
            "execution(* com.freesun.shop.service.imp.IndexImgServiceImpl.delete*(..))"*/
    @After("execution(* com.freesun.shop.service.imp.IndexImgServiceImpl.save*(..))"
            +" or " +
            "execution(* com.freesun.shop.service.imp.IndexImgServiceImpl.update*(..))"
            +" or " +
            "execution(* com.freesun.shop.service.imp.IndexImgServiceImpl.remove*(..))")
    public void deleteImgIndex(){
        System.out.println("进切面了");
        redisTemplate.delete("com.freesun.shop.entity.IndexImg::index-all-data");
    }
}
